package cn.assumejson.springframework.beans.context.event;

import cn.assumejson.springframework.beans.context.ApplicationEvent;
import cn.assumejson.springframework.beans.context.ApplicationListener;
import cn.assumejson.springframework.beans.factory.BeanFactory;

import java.util.concurrent.Executor;

/**
 * 异步发布
 *
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/12/2 0:14
 */
public class SimpleApplicationEventMulticaster extends AbstractApplicationEventMulticaster {

    private Executor taskExecutor;

    /**
     * Create a new SimpleApplicationEventMulticaster.
     */
    public SimpleApplicationEventMulticaster() {
    }

    /**
     * Create a new SimpleApplicationEventMulticaster for the given BeanFactory.
     */
    public SimpleApplicationEventMulticaster(BeanFactory beanFactory) {
        setBeanFactory(beanFactory);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void multicastEvent(final ApplicationEvent event) {
        for (final ApplicationListener listener : getApplicationListeners(event)) {
            listener.onApplicationEvent(event);
        }
    }
}
